package com.central.rearService.service.serviceImp

import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.central.common.entity.Visit
import com.central.common.model.CommonResult
import com.central.common.model.SysUser
import com.central.common.model.success
import com.central.common.service.impl.SuperServiceImpl
import com.central.rearService.mapper.VisitMapper
import com.central.rearService.service.VisitService
import org.springframework.stereotype.Service

/**
 * @author  fly
 * @date  2021/5/26 14:53
 * @version 1.0
 */
@Service
open class VisitServiceImp : SuperServiceImpl<VisitMapper, Visit>(), VisitService {


    override fun saveVisit(visitUserId: Long, sysUser: SysUser): CommonResult<Boolean> = success(
        save(Visit(visitUserId = sysUser.id).apply { createBy = visitUserId })
    , "操作成功")

    override fun getMyVisitUserId(userId: Long): List<String>? = list(KtQueryWrapper(Visit::class.java)
        .eq(Visit::createBy, userId).orderByDesc(Visit::createTime))
        .takeIf { it.isNotEmpty() }?.run { mapNotNull { it.visitUserId.toString() } }

}